/**************************************************************************************
 *
 * @(#) AsyncConfig.java
 * @Package com.jgdt.jgdtkasannong_university_gene_backend.config.async
 **************************************************************************************/
package com.jgdt.jgdtkasannong_university_gene_backend.config.async;

import com.alibaba.ttl.threadpool.TtlExecutors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.*;

/**
 * @description: 线程池配置
 * @author: huangAn
 * @createDate: 2025/04/28
 */
@Configuration
@EnableAsync
public class AsyncConfig {

    @Bean("taskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(100);
        executor.setThreadNamePrefix("Async-");
        executor.initialize();
        return executor;

//        // 使用 TtlExecutors 装饰线程池
//        return TtlExecutors.getTtlExecutor(
//                new ThreadPoolExecutor(
//                        10, 50, 60L, TimeUnit.SECONDS,
//                        new LinkedBlockingQueue<>(100),
//                        Executors.defaultThreadFactory()
//                )
//        );
    }
}



